package com.service.impl;

import com.mapper.ShopCommentMapper;
import com.pojo.ShopComment;
import com.pojo.ShopCommentExample;
import com.service.ShopCommentService;
import com.util.ServerResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * User: HL
 * Date: 2020/3/3
 * Time: 14:34
 * Description: No Description
 */
@Service
public class ShopCommentServiceImpl implements ShopCommentService {
    @Autowired
    private ShopCommentMapper shopCommentMapper;

    @Override
    public ServerResponse save(ShopComment shopComment) {
        Byte status =1;
        shopComment.setStatus(status);
        //执行mybatis添加方法
        int rows = shopCommentMapper.insert(shopComment);
        //判断添加成功
        if (rows > 0)
            return ServerResponse.addSuccess();
        else
            return ServerResponse.addFailed();
    }

    @Override
    public ServerResponse modifyStatus(Integer id) {
        ShopComment shopComment = shopCommentMapper.selectByPrimaryKey(id);
        Byte status = 0;
        shopComment.setStatus(status);
        int i = shopCommentMapper.updateByPrimaryKeySelective(shopComment);
        if (i>0)
            return ServerResponse.deleteSuccess();
        return ServerResponse.deleteFailed();
    }

    @Override
    public ServerResponse modify(ShopComment shopComment) {
        int i = shopCommentMapper.updateByPrimaryKeySelective(shopComment);
        if (i>0)
            return ServerResponse.updateSuccess();
        return ServerResponse.updateFailed();
    }

    @Override
    public ServerResponse getById(Integer id) {
        ShopComment shopComment = shopCommentMapper.selectByPrimaryKey(id);
        return ServerResponse.getDataSuccess(shopComment);
    }

    @Override
    public ServerResponse getAll() {
        ShopCommentExample example=new ShopCommentExample();
        ShopCommentExample.Criteria criteria = example.createCriteria();
        Byte status = 1;
        criteria.andStatusEqualTo(status);
        List<ShopComment> shopComments = shopCommentMapper.selectByExample(example);
        if (shopComments!=null&&shopComments.size()>0)
            return ServerResponse.getDataSuccess(shopComments);
        return ServerResponse.getDataFailed("没有数据");
    }


    @Override
    public ServerResponse getComment(String userId) {
        ShopCommentExample example=new ShopCommentExample();
        ShopCommentExample.Criteria criteria = example.createCriteria();
        Integer id = Integer.valueOf(userId);
        criteria.andUserIdEqualTo(id);
        List<ShopComment> shopComments = shopCommentMapper.selectByExample(example);
        return null;
    }
}
